package BasicClass.Four;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test_Fifteenth {
    public static void main(String[] args) throws IOException {
        BufferedReader buf= new BufferedReader(new InputStreamReader(System.in));
        String[] strs = buf.readLine().split(",");
        ListNode head = new ListNode(0);
        ListNode temp = head;
        for (int i = 0; i < strs.length; i++) {
            temp.next = new ListNode(Integer.parseInt(strs[i]));
            temp = temp.next;
        }
        ListNode list = insertionSortList(head.next);
        while (list != null){
            System.out.println(list.val+"-->");
        }
    }

    /**
     *使用插入排序对链表进行排序。
     * @param head
     * @return
     */
    public static ListNode insertionSortList (ListNode head) {
        // write code here
        if (head == null){
            return null;
        }
        ListNode pre = new ListNode(0);
        ListNode cur = head.next;
        pre.next = cur;
        while (cur != null){
            ListNode preHead = new ListNode(0);
            preHead.next = head;
            while (cur != preHead.next){
                if(cur.val < preHead.next.val){
                    pre.next = pre.next.next;
                    cur.next = preHead.next;
                    preHead.next = cur;
                    break;
                }
                preHead = preHead.next;
            }
            cur = cur.next;
        }
        return head;
    }

    public static class ListNode {
       int val;
       ListNode next = null;

       ListNode(int val){
           this.val = val;
       }
    }
}
